import { Modal, Button,message } from 'antd';
import React,{useState} from 'react';
import SearchInput from '../searchList/index';
import axios from 'axios';

const App = ({row, isVisible, onClose}) => {

  const [value, setValue] = useState(-1)

  const handleOk = () => {
    onClose(false);
    if(value>=1){
      axios.post('http://localhost:8080/tlistandsong/create',{
        idList:value,
        idSong: row
      }).then((res)=>{
        if(res.data===1){
          message.success("添加成功")
        }
      }).catch((res)=>{
        message.warn("歌曲已经存在于目标歌单")
        console.log("res",res)
      })
    }
  };

  const handleCancel = () => {
    onClose(false);
  };

  const getValue = (value1)=>{
    setValue(value1);
  }

  return (
    <>
      <Modal
        title="Title"
        visible={isVisible}
        onOk={handleOk}
        // confirmLoading={confirmLoading}
        onCancel={handleCancel}
      >
        选择歌单：<SearchInput getValue={getValue} value={value} />
      </Modal>
    </>
  );
};

export default App;